package cn.lanqiao.Test;

import cn.lanqiao.mapper.OrderMapper;
import cn.lanqiao.mapper.RoleMapper;
import cn.lanqiao.mapper.UserMapper;
import cn.lanqiao.pojo.Orders;
import cn.lanqiao.pojo.Role;
import cn.lanqiao.pojo.Users;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.ResourceBundle;

public class Test {
    private RoleMapper mapper=null;
    private SqlSession sqlSession=null;
    @Before
    public void init() throws IOException {
        String resource="mybatis-config.xml";
        InputStream inputStream= Resources.getResourceAsStream(resource);
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory=sqlSessionFactoryBuilder.build(inputStream);
        sqlSession=sqlSessionFactory.openSession();
        mapper=sqlSession.getMapper(RoleMapper.class);
    }
 /*   @org.junit.Test
    public void test1(){
        Orders orders= mapper.selectOrderAndUserByOid(1);
        System.out.println(orders);
    }*/
   /* @org.junit.Test
    public void test2(){
        Users users=mapper.selectUserByUid(1);
        System.out.println(users);
    }*/
    @org.junit.Test
    public  void selectAllRoleTest(){
        RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);
        List<Role> roleList = roleMapper.selectAll();
        for(Role role : roleList){
            System.out.println(role);
        }
    }
}
